package com.yc.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.yc.bean.DinnerTableBean;
import com.yc.bean.FoodDetailBean;
import com.yc.mapper.DinnerTableMapper;
import com.yc.mapper.FoodDetialMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zwei
 * @create 2024-10-07 15:50
 */
@Service
public class DetailBizImpl implements DetailBiz{
    private final FoodDetialMapper foodDetialMapper;
    private final DinnerTableMapper dinnerTableMapper;
    @Autowired
    public DetailBizImpl(FoodDetialMapper foodDetialMapper,DinnerTableMapper dinnerTableMapper) {
        this.foodDetialMapper = foodDetialMapper;
        this.dinnerTableMapper=dinnerTableMapper;
    }
    /**
     * 根据id获取菜品详情
     *
     * @return
     */
    @Override
    public List<FoodDetailBean> getfooddetail(Integer id) {
        QueryWrapper<FoodDetailBean> qw=new QueryWrapper<>();
        qw.eq("foodid",id).eq("disabled",0);
        List<FoodDetailBean> foodDetailBean = foodDetialMapper.selectList(qw);
        return foodDetailBean;
    }

    @Override
    public Boolean occupancy(Integer id) {
        UpdateWrapper<DinnerTableBean> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("table_status", 1)
                .eq("id", id);
        int i = dinnerTableMapper.update(null, updateWrapper);
        return i > 0;
    }

    @Override
    public Boolean release(Integer id) {
        UpdateWrapper<DinnerTableBean> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("table_status", 0)
                .eq("id", id);
        int i = dinnerTableMapper.update(null, updateWrapper);
        return i > 0;
    }
}
